package com.answer.petadoption.mapper;

import com.answer.petadoption.model.entity.User;
import org.apache.ibatis.annotations.*;

public interface UserMapper {
    @Select("SELECT * FROM user WHERE id = #{id} AND isDelete = 0")
    User getUserById(Long id);

    @Select("SELECT * FROM user WHERE userAccount = #{userAccount} AND isDelete = 0")
    User getUserByAccount(String userAccount);

    @Insert("INSERT INTO user (userName, userAccount, userAvatar, gender, userRole, userPassword, createTime, updateTime, isDelete) "
            + "VALUES (#{userName}, #{userAccount}, #{userAvatar}, #{gender}, #{userRole}, #{userPassword}, #{createTime}, #{updateTime}, #{isDelete})")
    void insertUser(User user);

    @Update("UPDATE user SET userName = #{userName}, userAccount = #{userAccount}, userAvatar = #{userAvatar}, gender = #{gender}, userRole = #{userRole}, "
            + "userPassword = #{userPassword}, updateTime = #{updateTime}, isDelete = #{isDelete} WHERE id = #{id}")
    void updateUser(User user);

    @Update("UPDATE user SET isDelete = 1 WHERE id = #{id}")
    void deleteUser(Long id);
}
